/*
 * Copyright (c) 2018. paascloud.net All Rights Reserved.
 * 项目名称：paascloud快速搭建企业级分布式微服务平台
 * 类名称：SecurityUser.java
 * 创建人：刘兆明
 * 联系方式：paascloud.net@gmail.com
 * 开源地址: https://github.com/paascloud
 * 博客地址: http://blog.paascloud.net
 * 项目官网: http://paascloud.net
 */

package com.weixing.oauth2.common.userdetails;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Map;

/**
 * The class Security user.
 *
 * @author kfc
 */
public class SecurityUser implements UserDetails {
	private static final long serialVersionUID = 4872628781561412463L;


	// 用户是否可用
	private  boolean  isEnable = true;

	// 权限
	private Collection< ? extends GrantedAuthority> authorities;

	/**
	 * 用户角色  代理商、后台管理员、会员
	*/
	private String userRole;

	private String loginName;

	private String loginPwd;
	/**
	 * 扩展数据(敏感数据)
	 */
	private Object sensitiveData;
	/**
	 * 扩展数据(非敏感数据)
	 */
	private Map<String,Object> extData;


	private String msgFlag ;

	private String openId;

	public SecurityUser() {
	}


	public SecurityUser(String loginName) {
		this.loginName = loginName;
	}


	public SecurityUser(String loginName, String loginPwd) {
		this.setLoginName(loginName);
		this.setLoginPwd(loginPwd);
	}

	public SecurityUser(String loginName, String loginPwd, String status) {
		this.setLoginName(loginName);
		this.setLoginPwd(loginPwd);
	}

	public SecurityUser(Collection<? extends GrantedAuthority> authorities, String loginName, String loginPwd) {
		this.authorities = authorities;
		this.loginName = loginName;
		this.loginPwd = loginPwd;
	}

	public SecurityUser(Collection<? extends GrantedAuthority> authorities, String loginName) {
		this.authorities = authorities;
		this.loginName = loginName;
	}


	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		return this.authorities;
	}

	@Override
	public String getPassword() {
		return this.getLoginPwd();
	}

	@Override
	public String getUsername() {
		return this.getLoginName();
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return isEnable();
	}


	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}


	public String getLoginPwd() {
		return loginPwd;
	}

	public void setLoginPwd(String loginPwd) {
		this.loginPwd = loginPwd;
	}

	public void setAuthorities(Collection<GrantedAuthority> authorities) {
		this.authorities = authorities;
	}

	public String getUserRole() {
		return userRole;
	}

	public void setUserRole(String userRole) {
		this.userRole = userRole;
	}

	public Object getSensitiveData() {
		return sensitiveData;
	}

	public void setSensitiveData(Object sensitiveData) {
		this.sensitiveData = sensitiveData;
	}

	public Map<String, Object> getExtData() {
		return extData;
	}

	public void setExtData(Map<String, Object> extData) {
		this.extData = extData;
	}

	public String getMsgFlag() {
		return msgFlag;
	}

	public void setMsgFlag(String msgFlag) {
		this.msgFlag = msgFlag;
	}

	public boolean isEnable() {
		return isEnable;
	}

	public void setEnable(boolean enable) {
		isEnable = enable;
	}

	public String getOpenId() {
		return openId;
	}

	public void setOpenId(String openId) {
		this.openId = openId;
	}
}
